package router

import (
	"LazyPig/pkg"
	"github.com/gin-gonic/gin"
	"net/http"
)

func Authorize() gin.HandlerFunc {
	return func(c *gin.Context) {
		token := c.Query("token") // 访问令牌
		//token := strings.Join(c.Request.Header["Token"], "")
		uid, success := pkg.CheckToken(token)
		if success {
			c.Set("uid", uid)
		} else {
			// 验证不通过，不再调用后续的函数处理
			c.AbortWithStatus(http.StatusUnauthorized)
		}
	}
}
